package com.frinder.base.wx;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;


/**
 * @author frinder
 * @date 2018/6/1
 * @className WebSocketConfig
 * @package com.fly.msg
 * @Description: WebSocket配置
 */
@Configuration("sockJsWebSocketConfig")
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
        // 注册 stomp 切点
        stompEndpointRegistry.addEndpoint("/endpointWisely").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 服务端发送消息域
        registry.enableSimpleBroker("/topic", "/client");
        // 点对点消息前缀
        registry.setUserDestinationPrefix("/client");
        // 客户端向服务端发送消息前缀
        registry.setApplicationDestinationPrefixes("/server");
    }
}
